package com.winsomely.leecode;

/**
 * 最后一个单词的长度
 * 
 * @author liujiawei
 *
 */
public class LengthOfLastWord {

	public int lengthOfLastWord(String s) {
		int max = 0;
		if (s == null || s.length() == 0) {
			return max;
		}
		for (int i = s.length() - 1; i >= 0; i--) {
			if (s.charAt(i) != ' ') {
				max++;
			} else if (max > 0) {
				break;
			}
		}
		return max;
	}

	public static void main(String[] args) {
		LengthOfLastWord t = new LengthOfLastWord();
		String s = "      ";
		System.out.println(t.lengthOfLastWord(s));
	}

}
